<template>
    <div class="containers">
        <div class="header">
            <img @click="goHome" src="../assets/images/pic_img2/btn_home.png" alt="">
            <img @click="goReturn" src="../assets/images/pic_img2/btn_return.png" alt="" style="margin-left: 37px;">
        </div>
        <div class="faceContent">
            <div class="lookFace" v-if="!status">请点击开始，正视人脸采集仪</div>
            <div class="lookFace1" v-else>正在采集中，请稍后</div>
            <img src="../assets/images/pic_img6/s.png" alt="" v-if="!status" class="buttonBegin" @click="beginFace">
        </div>
        <div class="footers">Copyright © 2025 动车入库作业智能登销记系统</div>


        <el-dialog :show-close="false" title="提示" :visible.sync="open" width="600px" append-to-body>
            <div style="margin: 40px auto;">{{ messages }}</div>
            <div style="margin-top:50px;">
                <el-button type="primary" @click="submitForm" class="buttons">确 定</el-button>
            </div>
        </el-dialog>
    </div>

</template>
<script>
import { entiretyFinish,singleFinish,getRegisterUser, queryWork, getContingencyUser, machinestart, operationType3 } from '@/api/home.js'
export default {
    data() {
        return {
            open: false,
            messages: '',
            status: false,
            ids: '',
            timer: null,
            type: 0,
            workStatus: null
        }
    },
    created() {
        this.ids = this.$route.query.id;
        this.workStatus = this.$route.query.workStatus;
        this.type = this.$route.query.type;
        this.typeStart = this.$route.query.typeStart;
        console.log(this.type,'typesss')

    },
    beforeDestroy() {
        clearInterval(this.timer);
    },
    methods: {
        submitForm() {
            this.open = false
            this.status = false
        },
        hasgetRegisterUser() {
            if (this.type == 2) {
                if (this.workStatus == 1) {
                    machinestart({
                        pageId: localStorage.getItem('pageId'),
                        type: this.typeStart,
                        workPlanId: this.ids
                    }).then(res => {
                        if (res.code == 40015) {
                            clearInterval(this.timer);
                            this.messages = res.msg
                            this.open = true
                            return;
                        }
                        if (res.personInfo) {
                            clearInterval(this.timer);
                            let data = JSON.stringify(res.personInfo)
                            this.$router.push(`/beginWork?datas=${data}&workStatus=${this.workStatus}`)
                        }

                    }).catch(() => {
                        clearInterval(this.timer);
                    })
                } else if (this.workStatus == 2) {
                    operationType3({
                       pageId: localStorage.getItem('pageId'),
                        type: this.typeStart,
                        workPlanId: this.ids
                    }).then(res => {
                        if (res.code == 40015) {
                            clearInterval(this.timer);
                            this.messages = res.msg
                            this.open = true

                            return;
                        }
                        if (res.workInfo) {
                            clearInterval(this.timer);
                            let data = JSON.stringify(res.workInfo)
                            this.$router.push(`/finishWork?datas=${data}&workStatus=${this.workStatus}`)
                        }
                    }).catch(() => {
                        clearInterval(this.timer);
                    })
                } else if (this.workStatus == 4) {
                    queryWork({
                       pageId: localStorage.getItem('pageId'),
                        type: this.typeStart,
                        workPlanId: this.ids
                    }).then(res => {
                        if (res.code == 40015) {
                            clearInterval(this.timer);
                            this.messages = res.msg
                            this.open = true

                            return;
                        }
                        if (res.workInfo) {
                            clearInterval(this.timer);
                            let data = JSON.stringify(res.workInfo)
                            this.$router.push(`/beginWork?datas=${data}&workStatus=${this.workStatus}`)
                        }
                    }).catch(() => {
                        clearInterval(this.timer);
                    })
                }
                else if (this.workStatus ==3) {
                    singleFinish({
                        pageId: localStorage.getItem('pageId'),
                        type: this.typeStart,
                        workPlanId: this.ids
                    }).then(res => {
                        if (res.code == 40015) {
                            clearInterval(this.timer);
                            this.messages = res.msg
                            this.open = true

                            return;
                        }
                        if (res.workInfo) {
                            clearInterval(this.timer);
                            let data = JSON.stringify(res.workInfo)
                            this.$router.push(`/finishWork?datas=${data}&workStatus=${this.workStatus}`)
                        }
                    }).catch(() => {
                        clearInterval(this.timer);
                    })
                }
            }
            if (this.type == 1) {
                getContingencyUser({
                    pageId: localStorage.getItem('pageId'),
                }).then(res => {
                    if (res.code == 40015) {
                        clearInterval(this.timer);
                        this.messages = res.msg
                        this.open = true
                        return;
                    }
                    if (res.data) {
                        clearInterval(this.timer);
                        this.$router.push(`/endWork?teamUserId=${res.data.teamUserId}&teamUser=${res.data.teamUser}$startTime=${res.data.startTime}`)
                        // this.$router.push(`/beginWork?datas=${data}`)
                    }
                }).catch(() => {
                    clearInterval(this.timer);
                })
            }

              if (this.type == 3) {
                entiretyFinish({
                        pageId: localStorage.getItem('pageId'),
                        type: this.typeStart,
                        workPlanId: this.ids
                    }).then(res => {
                        if (res.code == 40015) {
                            clearInterval(this.timer);
                            this.messages = res.msg
                            this.open = true
                            return;
                        }
                        if (res.workInfo) {
                            clearInterval(this.timer);
                            let data = JSON.stringify(res.workInfo)
                            this.$router.push(`/finishWork?datas=${data}&type=3`)
                        }

                    }).catch(() => {
                        clearInterval(this.timer);
                    })
            }

        },
        beginFace() {
            this.status = true
            this.timer = setInterval(() => {
                this.hasgetRegisterUser()
            }, 2000);
        },
        goReturn() {
            this.$router.go(-1)
        },
        goHome() {
            this.$router.push("/login")
        }
    }
}
</script>
<style lang="scss" scoped>
::v-deep .el-dialog {
    border-radius: 12px !important;
    position: fixed !important;
    width: 600px !important;
    // height: 320px !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    margin: 0 !important;
}

::v-deep .el-dialog__header {
    border-top-left-radius: 12px !important;
    border-top-right-radius: 12px !important;
    margin: auto !important;
    text-align: center !important;
    background: #1a6cd1 !important;
    color: #fff !important;
    padding-bottom: 0 !important;
    padding: 25px !important;
}

::v-deep .el-dialog__title {
    color: #fff !important;
    font-size: 30px;
}

::v-deep .el-dialog__body {
    margin: auto !important;
    text-align: center !important;
    font-size: 26px !important;
    color: #333 !important;
}

.buttons {
    width: 110px;
    height: 60px;
    font-size: 24px;
}

.containers {
    width: 100%;
    height: 100%;
    background-image: url("../assets/images/pic_img2/track_bg.jpg");
    background-size: cover;
    position: relative;

    .header {
        position: absolute;
        left: 569px;
        top: 186px;
    }

    .faceContent {
        position: absolute;
        top: 366px;
        left: calc((100% - 721px) / 2);
        width: 721px;
        height: 1125px;
        background-image: url("../assets/images/pic_img6/sl.png");
        background-size: 100% 100%;

        .lookFace {
            color: red;
            font-size: 26px;
            position: absolute;
            width: 340px;
            top: 840px;
            left: calc((100% - 340px) / 2);
        }

        .lookFace1 {
            color: red;
            font-size: 26px;
            position: absolute;
            width: 240px;
            top: 840px;
            left: calc((100% - 240px) / 2);
        }

        .buttonBegin {
            width: 200px;
            margin: auto;
            height: 90px;
            position: absolute;
            top: 900px;
            left: calc((100% - 200px) / 2);
            text-align: center;
        }
    }


}
</style>